package com.saifan.wyy_ov.ui.view;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import com.saifan.wyy_ov.data.bean.PermissionsBean;
import com.saifan.wyy_ov.data.bean.RoomInfoBean;
import com.saifan.wyy_ov.utils.ActivitysManager;

import java.util.List;
import lomasky.ma.httpUtils.JsonUtil;
import lomasky.ma.utils.SharedPrefUtil;

/**
 * @version V1.0.0
 * @author: lomasky
 * @date: 2015-05-04 15:46
 * @descrption
 */


public class BaseActivity extends AppCompatActivity {

    public List<PermissionsBean> getPermissions(){
        String per = SharedPrefUtil.getString(BaseActivity.this, "permissions", "");
        List<PermissionsBean> permissionsBeans = JsonUtil.getList(per,  PermissionsBean.class);
        return permissionsBeans;
    }

    public RoomInfoBean getRoomInfoBean() {
        if (roomInfoBean == null) {
            roomInfoBean = JsonUtil.getObject(SharedPrefUtil.getString(this, "roomInfo", ""), RoomInfoBean.class);
        }
        return roomInfoBean;

    }

    private Toolbar toolbar;

    public void setRoomInfoBean(RoomInfoBean roomInfoBean) {

        SharedPrefUtil.putString(this, "roomInfo", JsonUtil.toJson(roomInfoBean));
        this.roomInfoBean = roomInfoBean;

    }

    protected RoomInfoBean roomInfoBean;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivitysManager.getManager().addActivity(this);

    }



    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        return super.onCreateOptionsMenu(menu);
    }


    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == android.R.id.home) {
            this.finish();
        }
        return super.onOptionsItemSelected(item);
    }
    public void startActivity(Class clazz) {
        startActivity(new Intent(this, clazz));
    }
    public boolean isEmpty(TextView view) {
        return view.getText().toString().trim().isEmpty();
    }
}
